package cn.elead.chaos.sso.server.web.pwd.service.impl;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import cn.elead.chaos.email.domain.CustomMailMessage;
import cn.elead.chaos.email.service.ISubjectAttachService;

@Service
public class EmailAttachService implements ISubjectAttachService {

	@Override
	public void loadSubjectContext(CustomMailMessage message) {

		// 通过subjectId获取邮件主题和模板
		message.setSubject("易立德 | 重置密码信息");
		String content = "<html>\n" + 
				"<style>\n" + 
				".qmbox .email-body {\n" + 
				"	color: #40485B;\n" + 
				"	font-size: 14px;\n" + 
				"	font-family: -apple-system, \"Helvetica Neue\", Helvetica, \"Nimbus Sans L\",\n" + 
				"		\"Segoe UI\", Arial, \"Liberation Sans\", \"PingFang SC\", \"Microsoft YaHei\",\n" + 
				"		\"Hiragino Sans GB\", \"Wenquanyi Micro Hei\", \"WenQuanYi Zen Hei\",\n" + 
				"		\"ST Heiti\", SimHei, \"WenQuanYi Zen Hei Sharp\", sans-serif;\n" + 
				"	background: #f8f8f8;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .pull-right {\n" + 
				"	float: right;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox a {\n" + 
				"	color: #FE7300;\n" + 
				"	text-decoration: underline;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox a:hover {\n" + 
				"	color: #fe9d4d;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox a:active {\n" + 
				"	color: #b25100;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .logo {\n" + 
				"	text-align: center;\n" + 
				"	margin-bottom: 20px;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .panel {\n" + 
				"	background: #fff;\n" + 
				"	border: 1px solid #E3E9ED;\n" + 
				"	margin-bottom: 10px;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .panel-header {\n" + 
				"	font-size: 18px;\n" + 
				"	line-height: 30px;\n" + 
				"	padding: 10px 20px;\n" + 
				"	background: #fcfcfc;\n" + 
				"	border-bottom: 1px solid #E3E9ED;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .panel-body {\n" + 
				"	padding: 20px;\n" + 
				"	line-height: 1.7;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .container {\n" + 
				"	width: 100%;\n" + 
				"	max-width: 600px;\n" + 
				"	padding: 20px;\n" + 
				"	margin: 0 auto;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .text-center {\n" + 
				"	text-align: center;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .thumbnail {\n" + 
				"	padding: 4px;\n" + 
				"	max-width: 100%;\n" + 
				"	border: 1px solid #E3E9ED;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .btn-primary {\n" + 
				"	color: #fff;\n" + 
				"	font-size: 16px;\n" + 
				"	padding: 8px 14px;\n" + 
				"	line-height: 20px;\n" + 
				"	border-radius: 2px;\n" + 
				"	display: inline-block;\n" + 
				"	background: #FE7300;\n" + 
				"	text-decoration: none;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .btn-primary:hover, .qmbox .btn-primary:active {\n" + 
				"	color: #fff;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .footer {\n" + 
				"	color: #9B9B9B;\n" + 
				"	font-size: 12px;\n" + 
				"	margin-top: 20px;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .footer a {\n" + 
				"	color: #9B9B9B;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .footer a:hover {\n" + 
				"	color: #fe9d4d;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .footer a:active {\n" + 
				"	color: #b25100;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher {\n" + 
				"	line-height: 26px;\n" + 
				"	color: #40485B;\n" + 
				"	font-size: 16px;\n" + 
				"	padding: 0px;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .container, .qmbox .email-body#mail_to_teacher .panel-body\n" + 
				"	{\n" + 
				"	padding: 0px;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .container {\n" + 
				"	padding-top: 20px;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .textarea {\n" + 
				"	padding: 32px;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .say-hi {\n" + 
				"	font-weight: 500;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .paragraph {\n" + 
				"	margin-top: 24px;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .paragraph .pro-name {\n" + 
				"	color: #000000;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .paragraph.link {\n" + 
				"	margin-top: 32px;\n" + 
				"	text-align: center;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .paragraph.link .button {\n" + 
				"	background: #4A90E2;\n" + 
				"	border-radius: 2px;\n" + 
				"	color: #FFFFFF;\n" + 
				"	text-decoration: none;\n" + 
				"	padding: 11px 17px;\n" + 
				"	line-height: 14px;\n" + 
				"	display: inline-block;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher ul.pro-desc {\n" + 
				"	list-style-type: none;\n" + 
				"	margin: 0px;\n" + 
				"	padding: 0px;\n" + 
				"	padding-left: 16px;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher ul.pro-desc li {\n" + 
				"	position: relative;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher ul.pro-desc li::before {\n" + 
				"	content: '';\n" + 
				"	width: 3px;\n" + 
				"	height: 3px;\n" + 
				"	border-radius: 50%;\n" + 
				"	background: red;\n" + 
				"	position: absolute;\n" + 
				"	left: -15px;\n" + 
				"	top: 11px;\n" + 
				"	background: #40485B;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .blackboard-area {\n" + 
				"	height: 600px;\n" + 
				"	padding: 40px;\n" + 
				"	background-image: url();\n" + 
				"	color: #FFFFFF;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .blackboard-area .big-title {\n" + 
				"	font-size: 32px;\n" + 
				"	line-height: 45px;\n" + 
				"	text-align: center;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .blackboard-area .desc {\n" + 
				"	margin-top: 8px;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .blackboard-area .desc p {\n" + 
				"	margin: 0px;\n" + 
				"	text-align: center;\n" + 
				"	line-height: 28px;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .blackboard-area .card:nth-child(odd)\n" + 
				"	{\n" + 
				"	float: left;\n" + 
				"	margin-top: 45px;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .blackboard-area .card:nth-child(even)\n" + 
				"	{\n" + 
				"	float: right;\n" + 
				"	margin-top: 45px;\n" + 
				"}\n" + 
				"\n" + 
				".qmbox .email-body#mail_to_teacher .blackboard-area .card .title {\n" + 
				"	font-size: 18px;\n" + 
				"	text-align: center;\n" + 
				"	margin-bottom: 10px;\n" + 
				"}\n" + 
				"</style>\n" + 
				"<body>\n" + 
				"	<div id=\"mailContentContainer\"\n" + 
				"		class=\"qmbox qm_con_body_content qqmail_webmail_only\" style=\"\">\n" + 
				"		<div class=\"email-body\">\n" + 
				"			<div class=\"container\">\n" + 
				"				<div class=\"logo\">\n" + 
				"					<img height=\"30\" src=\"${baseUrl}/images/logo.png\">\n" + 
				"				</div>\n" + 
				"				<div class=\"panel\">\n" + 
				"					<div class=\"panel-header\">密码重置</div>\n" + 
				"					<div class=\"panel-body\">\n" + 
				"						<p>\n" + 
				"							<span>您好</span>\n" + 
				"							<a href=\"mailto:${email}\" rel=\"noopener\" target=\"_blank\">\n" + 
				"								${name}\n" + 
				"							</a>\n" + 
				"						</p>\n" + 
				"						<p>您已经请求了重置密码，可以点击下面的链接来重置密码。</p>\n" + 
				"						<p>\n" + 
				"							<a href=\"${link}\"\n" + 
				"								rel=\"noopener\" target=\"_blank\">${link}</a>\n" + 
				"						</p>\n" + 
				"						<p>如果您没有请求重置密码，请忽略这封邮件。</p>\n" + 
				"						<p>在您点击上面链接修改密码之前，您的密码将会保持不变。</p>\n" + 
				"					</div>\n" + 
				"				</div>\n" + 
				"			</div>\n" + 
				"		</div>\n" + 
				"	</div>\n" + 
				"</body>\n" + 
				"<style type=\"text/css\">\n" + 
				".qmbox style, .qmbox script, .qmbox head, .qmbox link, .qmbox meta {\n" + 
				"	display: none !important;\n" + 
				"}\n" + 
				"</style>\n" + 
				"</html>";
		 message.setText(content);

	}

	@Override
	public void loadAttachment(CustomMailMessage message) {

		Map<String, File> attachments = new HashMap<String, File>();

		// 添加附件
		File qrCode = new File("wxgzh8cm.jpg");
		// 建议文件带上后缀，可支持在线预览
		attachments.put("公众号二维码.jpg", qrCode);

		message.setAttachments(attachments);

	}

	@Override
	public void loadResource(CustomMailMessage message) {
		// TODO Auto-generated method stub
	}

}
